import 'dart:async';

import 'package:learning_content_admin_pannel.core/core/domain/clients/api_client.dart';
import 'package:learning_content_admin_pannel.core/core/domain/entities/access_credentials.dart';
import 'package:learning_content_admin_pannel.core/core/domain/repositories/user_repository/repository.dart';

abstract class HandleAccessCredentialUpdate {
  void call({
    required AccessCredentials? accessCredentials,
  });
}

class HandleAccessCredentialUpdateImpl implements HandleAccessCredentialUpdate {
  const HandleAccessCredentialUpdateImpl({
    required UserRepository userRepository,
    required ApiClient apiClient,
  })  : _userRepository = userRepository,
        _apiClient = apiClient;

  final UserRepository _userRepository;
  final ApiClient _apiClient;

  @override
  void call({
    required AccessCredentials? accessCredentials,
  }) {
    _apiClient.setAccessCredentials(accessCredentials);

    unawaited(_userRepository.saveAccessCredentials(
      accessCredentials: accessCredentials,
    ));
  }
}
